﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UIControllTool {
    
    public class InitUserControl : InitUserControlData {
        public UserControl userControl;
        public static Form Form;
        
        public void SavePropertiesToParentHashTable() {
            Type currentType = GetType();
            FieldInfo [] properties = currentType.GetFields (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance| BindingFlags.DeclaredOnly|BindingFlags.Static);

            foreach (FieldInfo property in properties) {
                object value = property.GetValue(this);
                SaveControlData[property.Name] = value;
            }
        }
        public void FundMethodRun(string  Property,object Value) { 
            MethodInfo method = this.GetType().GetMethod("Set" + Property);
            if (method != null) {
                method.Invoke(this, new object[] { Value });
            }
        }
        public void IntiControlData() {

            foreach (string item in SaveControlData.Keys) {
                FundMethodRun(item, SaveControlData[item]);
            }
        }
    }
}
